import requests
import os
import zipfile

def download_zip(filename, urls):
    print(f"{filename} downloading...")
    for i, url in enumerate(urls):
        response = requests.get(url, stream=True)
        with open( filename[i], 'wb') as f:
            for chunk in response.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
    print("Done!")
    unzip(filename)

def unzip(files):
    print(f"unzip file {files}")
    for zfile in files:
        f = zipfile.ZipFile(zfile, 'r')
        for file in f.namelist():
            f.extract(file, os.path.join(os.path.dirname(zfile)))
    print("Done!")


if __name__ == "__main__":
    files = ["data/har.zip"]
    urls = ["https://archive.ics.uci.edu/ml/machine-learning-databases/00240/UCI%20HAR%20Dataset.zip"]
    download_zip(files, urls)